<template>
  <div class="leisure-activity-survey">
    <div class="header">
      <h1>{{ surveyConfig.title }}</h1>
      <p class="subtitle">{{ surveyConfig.subtitle }}</p>
      <div class="header-actions">
        <button @click="goToHome" class="home-btn">
          <span class="home-icon">🏠</span> {{ surveyConfig.ui.buttons.home }}
        </button>
        <button @click="showSettings = true" class="settings-btn">
          <span class="settings-icon">⚙️</span> {{ surveyConfig.ui.buttons.settings }}
        </button>
      </div>
    </div>

    <!-- 设置页面 -->
    <div class="settings-modal" v-if="showSettings">
      <div class="settings-content">
        <div class="settings-header">
          <h2>{{ surveyConfig.settings.title }}</h2>
          <button @click="closeSettings" class="close-btn">×</button>
        </div>

        <div class="settings-form">
          <div class="form-group">
            <label>问答编号：<span class="required">*</span></label>
            <input type="text" v-model="recorderInfo.surveyId" placeholder="请输入问答编号（用于区分不同组的问卷）" maxlength="20">
            <p class="field-hint">编号用于区分不同组的问卷，建议使用如：LEISURE001、ACTIVITY_A等格式</p>
          </div>
          <div class="form-group">
            <label>记录人姓名：<span class="required">*</span></label>
            <input type="text" v-model="recorderInfo.name" placeholder="请输入记录人姓名">
          </div>
          <div class="form-group">
            <label>记录人职务/身份：<span class="required">*</span></label>
            <input type="text" v-model="recorderInfo.position" placeholder="请输入职务或身份（如：医生、护士、研究员等）">
          </div>
          <div class="form-group">
            <label>所属机构：</label>
            <input type="text" v-model="recorderInfo.institution" placeholder="请输入所属医院或机构名称">
          </div>
          <div class="form-group">
            <label>联系方式：</label>
            <input type="text" v-model="recorderInfo.contact" placeholder="请输入联系电话或邮箱">
          </div>
          <div class="form-group">
            <label>默认备注：</label>
            <textarea v-model="recorderInfo.defaultRemarks" placeholder="请输入默认备注信息（可选）" rows="3"></textarea>
          </div>
        </div>

        <div class="settings-actions">
          <button @click="saveRecorderInfo" class="save-settings-btn">保存设置</button>
          <button @click="closeSettings" class="cancel-btn">取消</button>
        </div>
      </div>
    </div>

    <!-- 记录人信息显示 -->
    <div class="recorder-info-display" v-if="recorderInfo.name && !showSettings && !showResult && !showExport">
      <div class="recorder-card">
        <div class="recorder-main-info">
          <h3>问答编号：{{ recorderInfo.surveyId }}</h3>
          <p>记录人：{{ recorderInfo.name }} | {{ recorderInfo.position }}</p>
          <p v-if="recorderInfo.institution">{{ recorderInfo.institution }}</p>
        </div>
        <div class="recorder-actions">
          <button @click="showSettings = true" class="edit-recorder-btn">编辑</button>
          <button @click="showExportDialog" class="export-btn">{{ surveyConfig.ui.buttons.export }}</button>
        </div>
      </div>
    </div>

    <!-- 导出数据模态框 -->
    <div class="export-modal" v-if="showExport">
      <div class="export-content">
        <div class="export-header">
          <h2>{{ surveyConfig.export.title }}</h2>
          <button @click="closeExport" class="close-btn">×</button>
        </div>

        <div class="export-form">
          <div class="export-info">
            <p><strong>当前问答编号：</strong>{{ recorderInfo.surveyId }}</p>
            <p><strong>导出说明：</strong>将从服务器打包当前编号的所有空闲活动评估数据</p>
          </div>

          <div class="form-group">
            <label>导出密码：<span class="required">*</span></label>
            <input type="password" v-model="exportPassword" placeholder="请输入导出密码" @keyup.enter="exportData">
            <p class="field-hint">请联系管理员获取导出密码</p>
          </div>

          <div class="export-options">
            <div class="form-group">
              <label>
                <input type="checkbox" v-model="exportOptions.includeRawData">
                包含原始评估数据
              </label>
            </div>
            <div class="form-group">
              <label>
                <input type="checkbox" v-model="exportOptions.includeStatistics">
                包含统计分析
              </label>
            </div>
          </div>
        </div>

        <div class="export-actions">
          <button @click="exportData" class="export-confirm-btn" :disabled="!exportPassword">
            <span v-if="!isExporting">导出压缩包</span>
            <span v-else>导出中...</span>
          </button>
          <button @click="closeExport" class="cancel-btn">取消</button>
        </div>
      </div>
    </div>

    <!-- 表单 -->
    <div class="survey-form" v-if="!showResult && !showSettings && !showExport">
      <p class="instruction">{{ surveyConfig.instruction }}</p>

      <!-- 基本信息 -->
      <div class="section">
        <h2>{{ surveyConfig.sections.basicInfo.title }}</h2>
        <div class="form-grid">
          <div class="form-group" v-for="field in surveyConfig.sections.basicInfo.fields" :key="field.name">
            <label>{{ field.label }}：<span v-if="field.required" class="required">*</span></label>
            <input
              v-if="field.type === 'text' || field.type === 'number' || field.type === 'tel' || field.type === 'date'"
              :type="field.type" v-model="formData[field.name]" :placeholder="field.placeholder" :min="field.min"
              :max="field.max" :step="field.step">
            <textarea v-else-if="field.type === 'textarea'" v-model="formData[field.name]"
              :placeholder="field.placeholder" :rows="field.rows"></textarea>
            <div v-else-if="field.type === 'radio'" class="radio-group">
              <label v-for="option in field.options" :key="option.value">
                <input type="radio" v-model="formData[field.name]" :value="option.value"> {{ option.label }}
              </label>
            </div>
          </div>
        </div>
      </div>

      <!-- 空闲活动频率评估 -->
      <div class="section">
        <h2>{{ surveyConfig.sections.assessment.title }}</h2>
        <p class="assessment-description">{{ surveyConfig.sections.assessment.description }}</p>
        
        <!-- 频率说明 -->
        <div class="info-box">
          <h4>频率说明：</h4>
          <ul>
            <li v-for="option in surveyConfig.frequencyOptions" :key="option.value">
              {{ option.label }}
            </li>
          </ul>
        </div>

        <!-- 活动列表 -->
        <div class="activities-list">
          <div v-for="activity in surveyConfig.leisureActivities" :key="activity.id" class="activity-item">
            <label class="activity-label">
              {{ activity.label }}<span v-if="activity.required" class="required">*</span>
            </label>
            <div class="frequency-options">
              <label v-for="option in surveyConfig.frequencyOptions" :key="option.value" class="frequency-option">
                <input 
                  type="radio" 
                  :name="activity.id" 
                  :value="option.value" 
                  v-model="formData[activity.id]">
                <span>{{ option.value }}</span>
              </label>
            </div>
          </div>
        </div>

        <!-- 健身器材问题 -->
        <div class="fitness-equipment-section" v-if="shouldShowFitnessEquipment">
          <h3>您在使用健身器材锻炼的过程中，最经常使用的是哪种？（最多选择3项）</h3>
          
          <!-- 健身器材图片 -->
          <div class="equipment-image-container">
            <img :src="fitnessEquipmentImage" alt="健身器材示意图" class="equipment-image" />
          </div>
          
          <!-- 健身器材选择选项 -->
          <div class="equipment-options">
            <label v-for="option in surveyConfig.fitnessEquipmentOptions" :key="option.value" class="equipment-option">
              <input 
                type="checkbox" 
                :value="option.value" 
                v-model="formData.fitnessEquipment"
                @change="handleFitnessEquipmentChange">
              <span>{{ option.label }}</span>
            </label>
          </div>
          <p v-if="formData.fitnessEquipment && formData.fitnessEquipment.length > 3" class="error-message">
            最多只能选择3项
          </p>
        </div>
      </div>

      <!-- 提交按钮 -->
      <div class="form-actions">
        <button @click="calculateResult" class="submit-btn" :disabled="!isFormValid">
          {{ surveyConfig.ui.buttons.submit }}
        </button>
      </div>
    </div>

    <!-- 结果展示 -->
    <div class="result-section" v-if="showResult">
      <h2>空闲活动频率评估结果</h2>
      <div class="result-card">
        <div class="result-summary">
          <h3>评估完成</h3>
          <p class="average-score">平均分：{{ result.averageScore.toFixed(2) }}</p>
          <p class="participation-level" :style="{ color: result.participationLevel.color }">
            活动参与度：{{ result.participationLevel.level }}
          </p>
          <p class="participation-description">{{ result.participationLevel.description }}</p>
        </div>

        <div class="result-details">
          <h4>统计信息：</h4>
          <ul>
            <li>总得分：{{ result.totalScore }}</li>
            <li>平均分：{{ result.averageScore.toFixed(2) }}</li>
            <li>已回答项数：{{ result.answeredCount }}/{{ surveyConfig.leisureActivities.length }}</li>
            <li>从不参加：{{ result.statistics.neverParticipate }} 项</li>
            <li>一年数次：{{ result.statistics.yearlyParticipate }} 项</li>
            <li>一月数次：{{ result.statistics.monthlyParticipate }} 项</li>
            <li>一周数次：{{ result.statistics.weeklyParticipate }} 项</li>
            <li>几乎每天：{{ result.statistics.dailyParticipate }} 项</li>
            <li v-if="result.fitnessEquipment && result.fitnessEquipment.length > 0">
              常用健身器材：{{ result.fitnessEquipment.join(', ') }}
            </li>
          </ul>
        </div>

        <div class="action-buttons">
          <button @click="saveToBackendOnly" class="save-btn" :disabled="isSaving">
            <span v-if="!isSaving">保存结果</span>
            <span v-else>保存中...</span>
          </button>
          <button @click="resetForm" class="reset-btn">{{ surveyConfig.ui.buttons.restart }}</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { leisureActivityConfig } from '@/config/leisureActivityConfig.js';
import { calculateLeisureActivityAssessment } from '@/config/leisureActivityLogic.js';
import fitnessEquipmentImage from '@/assets/图片 1.png';

export default {
  name: 'LeisureActivitySurvey',
  mounted() {
    // 自动设置当前日期
    const now = new Date();
    const year = now.getFullYear();
    const month = String(now.getMonth() + 1).padStart(2, '0');
    const day = String(now.getDate()).padStart(2, '0');
    this.formData.recordDate = `${year}-${month}-${day}`;

    // 加载记录人信息
    this.loadRecorderInfo();

    // 初始化表单数据
    this.initializeForm();
  },
  data() {
    return {
      surveyConfig: leisureActivityConfig,
      fitnessEquipmentImage: fitnessEquipmentImage, // 健身器材图片
      showResult: false,
      showSettings: false,
      showExport: false,
      isExporting: false,
      isSaving: false,
      exportPassword: '',
      // 记录人信息（设置）
      recorderInfo: {
        surveyId: '',
        name: '',
        position: '',
        institution: '',
        contact: '',
        defaultRemarks: ''
      },
      // 导出选项
      exportOptions: {
        includeRawData: true,
        includeStatistics: true
      },
      // 问卷表单数据
      formData: {
        fitnessEquipment: []
      },
      result: {
        activityScores: {},
        totalScore: 0,
        averageScore: 0,
        answeredCount: 0,
        frequencyDistribution: {},
        participationLevel: {},
        fitnessEquipment: [],
        statistics: {}
      }
    }
  },
  computed: {
    isFormValid() {
      // 检查基本信息
      if (!this.recorderInfo.surveyId || !this.recorderInfo.name || !this.recorderInfo.position) {
        return false;
      }
      // 个人信息字段已改为选填，不再进行必填验证
      
      // 检查至少填写一项活动频率
      let hasAnswer = false;
      this.surveyConfig.leisureActivities.forEach(activity => {
        if (this.formData[activity.id] && this.formData[activity.id] !== '') {
          hasAnswer = true;
        }
      });
      
      if (!hasAnswer) {
        return false;
      }
      
      // 检查健身器材选择（如果选择了健身器材锻炼）
      if (this.formData.fitnessEquipment && this.formData.fitnessEquipment.length > 3) {
        return false;
      }
      
      return true;
    },
    shouldShowFitnessEquipment() {
      // 如果选择了健身器材锻炼（Q07），且频率>=2，显示健身器材选择
      const fitnessScore = this.formData.Q07;
      return fitnessScore && parseInt(fitnessScore) >= 2;
    }
  },
  methods: {
    // 导航方法
    goToHome() {
      this.$router.push('/');
    },

    // 初始化表单数据
    initializeForm() {
      // 保留已设置的recordDate值
      const existingRecordDate = this.formData.recordDate;

      this.formData = {
        recordDate: existingRecordDate || '',
        fitnessEquipment: []
      };
    },

    // 处理健身器材选择变化
    handleFitnessEquipmentChange() {
      // 如果超过3项，移除最后一项
      if (this.formData.fitnessEquipment && this.formData.fitnessEquipment.length > 3) {
        this.formData.fitnessEquipment = this.formData.fitnessEquipment.slice(0, 3);
      }
    },

    // 设置相关方法
    saveRecorderInfo() {
      // 验证必填字段
      if (!this.recorderInfo.surveyId || !this.recorderInfo.name || !this.recorderInfo.position) {
        alert('请填写所有必填信息（问答编号、记录人姓名、职务/身份）！');
        return;
      }

      // 保存记录人信息到本地存储
      localStorage.setItem('leisureActivityRecorderInfo', JSON.stringify(this.recorderInfo));
      // 设置默认备注
      if (this.recorderInfo.defaultRemarks && !this.formData.remarks) {
        this.formData.remarks = this.recorderInfo.defaultRemarks;
      }
      this.showSettings = false;
      alert('记录人信息已保存！');
    },

    closeSettings() {
      this.showSettings = false;
    },

    loadRecorderInfo() {
      // 从本地存储加载记录人信息
      const saved = localStorage.getItem('leisureActivityRecorderInfo');
      if (saved) {
        this.recorderInfo = JSON.parse(saved);
        // 设置默认备注
        if (this.recorderInfo.defaultRemarks && !this.formData.remarks) {
          this.formData.remarks = this.recorderInfo.defaultRemarks;
        }
      }
    },

    // 导出相关方法
    showExportDialog() {
      this.showExport = true;
      this.exportPassword = '';
    },

    closeExport() {
      this.showExport = false;
      this.exportPassword = '';
      this.isExporting = false;
    },

    async exportData() {
      this.isExporting = true;

      try {
        // 发送导出请求到服务器
        const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/export-leisure-activity-survey`, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            surveyId: this.recorderInfo.surveyId,
            password: this.exportPassword,
            exportOptions: this.exportOptions
          })
        });

        if (response.status === 401) {
          alert('密码错误，请重新输入！');
          return;
        }

        if (!response.ok) {
          throw new Error('导出请求失败');
        }

        // 获取服务器返回的压缩包
        const blob = await response.blob();

        if (blob.size === 0) {
          alert('当前问答编号下没有空闲活动评估数据！');
          return;
        }

        // 下载服务器生成的压缩包
        const url = window.URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.href = url;
        link.download = `空闲活动评估数据_${this.recorderInfo.surveyId}_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.zip`;
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        window.URL.revokeObjectURL(url);

        alert('数据导出成功！');
        this.closeExport();
      } catch (error) {
        console.error('导出失败:', error);
        alert('导出失败，请检查网络连接或联系管理员！');
      } finally {
        this.isExporting = false;
      }
    },

    calculateResult() {
      // 使用空闲活动评估逻辑
      this.result = calculateLeisureActivityAssessment(this.formData);
      this.showResult = true;
    },

    async saveToBackendOnly() {
      this.isSaving = true;

      try {
        // 1. 保存问卷数据到后台
        await this.saveToBackend();

        // 2. 生成评估报告内容
        const timestamp = new Date().toLocaleString('zh-CN');
        const recordDate = this.formData.recordDate ?
          new Date(this.formData.recordDate).toLocaleString('zh-CN', { year: 'numeric', month: 'long', day: 'numeric' }) :
          timestamp;

        const frequencyLabels = {
          1: '从不参加',
          2: '一年数次',
          3: '一月数次',
          4: '一周数次',
          5: '几乎每天'
        };

        let activitiesText = '';
        this.surveyConfig.leisureActivities.forEach(activity => {
          const score = this.result.activityScores[activity.id];
          activitiesText += `${activity.label}：${score ? frequencyLabels[score] : '未填写'}\n`;
        });

        const content = `空闲活动频率评估结果报告
问答编号：${this.recorderInfo.surveyId}
生成时间：${timestamp}

=== 记录人信息 ===
记录人姓名：${this.recorderInfo.name}
记录人职务/身份：${this.recorderInfo.position}
所属机构：${this.recorderInfo.institution || '未填写'}
联系方式：${this.recorderInfo.contact || '未填写'}
记录日期：${recordDate}
备注：${this.formData.remarks || '无'}

=== 被评估人基本信息 ===
姓名：${this.formData.patientName}
编号：${this.formData.patientId || '未填写'}
日期：${recordDate}
年龄：${this.formData.age || '未填写'}岁
性别：${this.formData.gender === 'male' ? '男性' : this.formData.gender === 'female' ? '女性' : '未填写'}
联系电话：${this.formData.phone || '未填写'}
测量地点：${this.formData.measurementLocation || '未填写'}
测量人员：${this.formData.measurementPerson || '未填写'}

=== 空闲活动频率评估 ===
总得分：${this.result.totalScore}
平均分：${this.result.averageScore.toFixed(2)}
已回答项数：${this.result.answeredCount}/${this.surveyConfig.leisureActivities.length}
活动参与度：${this.result.participationLevel.level}
${this.result.participationLevel.description}

=== 各活动频率详情 ===
${activitiesText}

=== 频率分布统计 ===
从不参加：${this.result.statistics.neverParticipate} 项
一年数次：${this.result.statistics.yearlyParticipate} 项
一月数次：${this.result.statistics.monthlyParticipate} 项
一周数次：${this.result.statistics.weeklyParticipate} 项
几乎每天：${this.result.statistics.dailyParticipate} 项

${this.result.fitnessEquipment && this.result.fitnessEquipment.length > 0 ? `=== 常用健身器材 ===\n${this.result.fitnessEquipment.join(', ')}\n` : ''}
报告结束
`;

        // 3. 保存评估报告到@data/文件夹
        await this.saveFileToDataFolder(content);

        alert('✅ 数据已成功保存到后台！\n\n📁 问卷数据：survey_data/\n📄 评估报告：@data/');

      } catch (error) {
        console.error('保存到后台失败:', error);
        alert('❌ 保存失败，请检查网络连接或联系管理员！\n\n错误信息：' + error.message);
      } finally {
        this.isSaving = false;
      }
    },

    async saveToBackend() {
      // 构建问卷数据
      const surveyData = {
        surveyId: this.recorderInfo.surveyId,
        recordTime: new Date().toISOString(),
        recordDate: this.formData.recordDate,
        recorderName: this.recorderInfo.name,
        recorderPosition: this.recorderInfo.position,
        recorderInstitution: this.recorderInfo.institution,
        recorderContact: this.recorderInfo.contact,
        patientName: this.formData.patientName || "未填写",
        patientId: this.formData.patientId || null,
        age: this.formData.age || 0,
        gender: this.formData.gender || null,
        phone: this.formData.phone || null,
        measurementLocation: this.formData.measurementLocation || null,
        measurementPerson: this.formData.measurementPerson || null,
        remarks: this.formData.remarks || null,
        // 活动频率数据
        Q01: this.formData.Q01,
        Q02: this.formData.Q02,
        Q03: this.formData.Q03,
        Q04: this.formData.Q04,
        Q05: this.formData.Q05,
        Q06: this.formData.Q06,
        Q07: this.formData.Q07,
        Q08: this.formData.Q08,
        Q09: this.formData.Q09,
        Q10: this.formData.Q10,
        Q11: this.formData.Q11,
        Q12: this.formData.Q12,
        Q13: this.formData.Q13,
        Q14: this.formData.Q14,
        // 健身器材选择
        fitnessEquipment: this.formData.fitnessEquipment || [],
        // 计算结果
        totalScore: this.result.totalScore,
        averageScore: this.result.averageScore,
        answeredCount: this.result.answeredCount,
        frequencyDistribution: this.result.frequencyDistribution,
        participationLevel: this.result.participationLevel,
        statistics: this.result.statistics,
        createdAt: new Date().toISOString()
      };

      const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/save-leisure-activity-survey`, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(surveyData)
      });

      if (!response.ok) {
        throw new Error('保存问卷数据失败');
      }
    },

    async saveFileToDataFolder(content) {
      // 通过API保存文件到@data/文件夹
      const filename = `空闲活动频率评估结果_${this.recorderInfo.surveyId}_${this.formData.patientName}_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.txt`;

      const response = await fetch(`${window.location.protocol}//${window.location.hostname}:13000/api/save-file`, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          filename: filename,
          content: content,
          surveyId: this.recorderInfo.surveyId
        })
      });

      if (!response.ok) {
        throw new Error('保存评估报告失败');
      }
    },

    resetForm() {
      this.formData = {
        fitnessEquipment: []
      };
      this.result = {
        activityScores: {},
        totalScore: 0,
        averageScore: 0,
        answeredCount: 0,
        frequencyDistribution: {},
        participationLevel: {},
        fitnessEquipment: [],
        statistics: {}
      };
      this.showResult = false;
      // 重新设置日期
      const now = new Date();
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, '0');
      const day = String(now.getDate()).padStart(2, '0');
      this.formData.recordDate = `${year}-${month}-${day}`;
    }
  }
}
</script>

<style scoped>
.leisure-activity-survey {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.header {
  text-align: center;
  margin-bottom: 30px;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.header h1 {
  margin: 0 0 10px 0;
  font-size: 2.5em;
  font-weight: 300;
}

.subtitle {
  margin: 0 0 20px 0;
  font-size: 1.2em;
  opacity: 0.9;
}

.header-actions {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.home-btn,
.settings-btn {
  padding: 10px 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border-radius: 25px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.home-btn:hover,
.settings-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
}

/* 设置模态框样式 */
.settings-modal,
.export-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.settings-content,
.export-content {
  background: white;
  padding: 30px;
  border-radius: 15px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.settings-header,
.export-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #f0f0f0;
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #999;
  padding: 5px;
  border-radius: 50%;
  width: 35px;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background: #f0f0f0;
  color: #333;
}

/* 记录人信息显示 */
.recorder-info-display {
  margin-bottom: 30px;
}

.recorder-card {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 4px solid #667eea;
}

.recorder-main-info h3 {
  margin: 0 0 5px 0;
  color: #333;
}

.recorder-main-info p {
  margin: 5px 0;
  color: #666;
}

.recorder-actions {
  display: flex;
  gap: 10px;
}

.edit-recorder-btn,
.export-btn {
  padding: 8px 16px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.edit-recorder-btn:hover {
  background: #f0f0f0;
}

.export-btn {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.export-btn:hover {
  background: #5568d3;
}

/* 表单样式 */
.survey-form {
  background: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.instruction {
  font-size: 1.1em;
  color: #666;
  margin-bottom: 30px;
  padding: 15px;
  background: #f8f9fa;
  border-left: 4px solid #667eea;
  border-radius: 5px;
}

.section {
  margin-bottom: 40px;
}

.section h2 {
  color: #333;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #667eea;
}

.assessment-description {
  color: #666;
  margin-bottom: 15px;
}

.info-box {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 5px;
  margin-bottom: 20px;
  border-left: 4px solid #667eea;
}

.info-box h4 {
  margin: 0 0 10px 0;
  color: #333;
}

.info-box ul {
  margin: 0;
  padding-left: 20px;
  color: #666;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: #333;
  font-weight: 500;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 14px;
  box-sizing: border-box;
}

.form-group textarea {
  resize: vertical;
}

.required {
  color: #e74c3c;
}

.field-hint {
  font-size: 12px;
  color: #999;
  margin-top: 5px;
}

.radio-group {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: normal;
}

/* 活动列表样式 */
.activities-list {
  margin-bottom: 30px;
}

.activity-item {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 10px;
  margin-bottom: 15px;
  border: 2px solid #e9ecef;
}

.activity-label {
  display: block;
  font-weight: 600;
  color: #333;
  margin-bottom: 15px;
  font-size: 1.1em;
}

.frequency-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.frequency-option {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 15px;
  background: white;
  border: 2px solid #ddd;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.frequency-option:hover {
  border-color: #667eea;
  background: #f0f4ff;
}

.frequency-option input[type="radio"] {
  margin: 0;
  cursor: pointer;
}

.frequency-option input[type="radio"]:checked + span {
  font-weight: 600;
  color: #667eea;
}

.frequency-option span {
  font-size: 1.1em;
  color: #333;
}

/* 健身器材部分 */
.fitness-equipment-section {
  background: #fff9e6;
  padding: 20px;
  border-radius: 10px;
  margin-top: 30px;
  border-left: 4px solid #ffc107;
}

.fitness-equipment-section h3 {
  margin: 0 0 20px 0;
  color: #333;
}

.equipment-image-container {
  margin: 20px 0 30px 0;
  text-align: center;
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.equipment-image {
  max-width: 100%;
  max-height: 600px;
  height: auto;
  border-radius: 5px;
  display: block;
  margin: 0 auto;
  object-fit: contain;
}

.equipment-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.equipment-option {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 15px;
  background: white;
  border: 2px solid #ddd;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.equipment-option:hover {
  border-color: #ffc107;
  background: #fffbf0;
}

.equipment-option input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

.equipment-option input[type="checkbox"]:checked + span {
  font-weight: 600;
  color: #ffc107;
}

.error-message {
  color: #e74c3c;
  font-size: 14px;
  margin-top: 10px;
}

/* 按钮样式 */
.form-actions {
  text-align: center;
  margin-top: 30px;
}

.submit-btn {
  padding: 15px 40px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.3s ease;
}

.submit-btn:hover:not(:disabled) {
  background: #5568d3;
  transform: translateY(-2px);
}

.submit-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* 结果展示样式 */
.result-section {
  background: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.result-section h2 {
  color: #333;
  margin-bottom: 20px;
  text-align: center;
}

.result-card {
  background: #f8f9fa;
  padding: 30px;
  border-radius: 10px;
  border-left: 4px solid #667eea;
}

.result-summary {
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 2px solid #dee2e6;
}

.result-summary h3 {
  color: #667eea;
  margin-bottom: 10px;
}

.average-score {
  font-size: 1.5em;
  color: #333;
  margin: 10px 0;
}

.participation-level {
  font-size: 1.3em;
  font-weight: 600;
  margin: 10px 0;
}

.participation-description {
  color: #666;
  margin-top: 10px;
}

.result-details {
  margin-bottom: 20px;
}

.result-details h4 {
  color: #333;
  margin-bottom: 10px;
}

.result-details ul {
  list-style: none;
  padding: 0;
}

.result-details li {
  padding: 8px 0;
  border-bottom: 1px solid #e9ecef;
  color: #666;
}

.action-buttons {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-top: 30px;
}

.save-btn,
.reset-btn {
  padding: 12px 30px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.3s ease;
}

.save-btn {
  background: #28a745;
  color: white;
}

.save-btn:hover:not(:disabled) {
  background: #218838;
}

.save-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.reset-btn {
  background: #6c757d;
  color: white;
}

.reset-btn:hover {
  background: #5a6268;
}

/* 设置表单样式 */
.settings-form {
  margin-bottom: 20px;
}

.settings-actions,
.export-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.save-settings-btn,
.export-confirm-btn {
  padding: 10px 20px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.save-settings-btn:hover,
.export-confirm-btn:hover:not(:disabled) {
  background: #5568d3;
}

.export-confirm-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.cancel-btn {
  padding: 10px 20px;
  background: #6c757d;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.cancel-btn:hover {
  background: #5a6268;
}

.export-info {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 5px;
  margin-bottom: 20px;
}

.export-info p {
  margin: 5px 0;
  color: #666;
}

.export-options {
  margin-top: 15px;
}

.export-options .form-group {
  margin-bottom: 10px;
}

.export-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: normal;
}
</style>

